<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>INSPINIA | Basic Form</title>
    <link href="#springUrl('/static/css/plugins/bootstrap-table/bootstrap-table.min.css')" rel="stylesheet">
	<link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
	<link href="#springUrl('/static/css/style.css')" rel="stylesheet">
</head>
<body class="white-bg">
<div class="ibox-content" style="width: 430px;">
   <form id="myForm" class="form-horizontal" autocomplete="off" data-validator-option="{theme:'default'}">
       <div class="form-group"><label class="col-sm-2 control-label">分类等级</label>
           <div class="col-sm-10">
               <input type="hidden" class="form-control" value="2" name="categoryLevel" readonly="true" >
               <select class="form-control" name="pid">
                   <option value="1">护肤</option>
                   <option value="2">彩妆</option>
                   <option value="3">香氛</option>
                   <option value="4">美发</option>
                   <option value="5">美体/美甲</option>
                   <option value="6">个体护理</option>
                   <option value="7">男士</option>
                   <option value="8">其它</option>
               </select>
           </div>
       </div>
       <button class="btn btn-primary" onclick="addCategory(null)" type="button">
       <div class="hr-line-dashed"></div>
       <div class="form-group"><label class="col-sm-2 control-label">分类名称</label>
           <div class="col-sm-10">
           		<input type="text" class="form-control" name="categoryName" >
               <input type="hidden"  name="pid" value="0">
           </div>
       </div>
       <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="text-center">
                <button class="btn btn-primary" type="submit">提交</button>
            </div>
        </div>
    </form>
</div>
<script src="#springUrl('/static/js/jquery-2.1.1.js')"></script>
<script src="#springUrl('/static/plugins/nice-validator-0.8.1/jquery.validator.js?local=zh-CN')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table.min.js')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js')"></script>
<script src="#springUrl('/static/plugins/layer-v2.2/layer/layer.js')"></script>
<script src="#springUrl('/static/js/base_list.js')"></script>
<script src="#springUrl('/static/js/common.js')"></script>

<script type="text/javascript">
$("#myForm").validator({
    valid: function(form){
        var me = this;
        // 提交表单之前，hold住表单，防止重复提交
        me.holdSubmit();
        $.ajax({
        	url: "#springUrl('/item/itemcategory/addItemCategory')",
            data: $(form).serialize(),
            type: "POST",
            success: function(data){
            	var d = JSON.parse(data);
                if(d.success && d.data){
                	window.parent.location.reload();
                	//当你在iframe页面关闭自身时
                	//var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                	//parent.layer.close(index); //再执行关闭   
                } else {
                	//失败，提交表单成功后，释放hold，如果不释放hold，就变成了只能提交一次的表单
                    me.holdSubmit(false);
                }
            }
        });
    }

});
function addCategory(id){
    var title = "新增商品分类";
    var url = "#springUrl('/item/itemcategory/add.html')";
    layer.open({
        type: 2,
        title: title,
        shadeClose: true,
        shade: 0.8,
        area: ['600px', '430px'],
        fix: false,
        maxmin: true,
        content: url
    });
}
</script>
</body>
</html>
